package com.hq.fxh.No3_TuiGuang.MyMoBan.Adapter;

import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hq.fxh.R;

/**
 * /**
 *
 * @author 薛
 * @ClassName
 * @Description :
 * @Created 2017/9/10
 * @Email xlwenhao1858@sina.com
 */


public class MySpringAdapter extends BaseAdapter {
    int type = 0;
    String[] data;

    public void setData(String[] data) {
        this.data = data;
    }

    @Override
    public int getCount() {
        return data == null ? 0 : data.length;
    }

    @Override
    public Object getItem(int i) {
        return data[i];
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup parent) {
        View view = convertView;
        ViewHolder viewHolder = null;
        if (view == null || !(view.getTag() instanceof ViewHolder)) {
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_spring_item, null);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        switch (type) {
            case 0:
                viewHolder.textListPlateName.setGravity(Gravity.CENTER);
                break;
            case 1:
                viewHolder.textListPlateName.setGravity(Gravity.RIGHT);
                break;
        }

        viewHolder.textListPlateName.setText(data[i]);
        return view;
    }

    static class ViewHolder {
        protected TextView textListPlateName;
        protected LinearLayout layoutListPlateName;

        ViewHolder(View rootView) {
            initView(rootView);
        }

        private void initView(View rootView) {
            textListPlateName = (TextView) rootView.findViewById(R.id.text_List_PlateName);
            layoutListPlateName = (LinearLayout) rootView.findViewById(R.id.layout_List_PlateName);
        /*    textListPlateName.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    LogUtils.e("点击事件"+textListPlateName.getText());
                }
            });*/
        }
    }

    public void setType(int type) {
        this.type = type;

    }
}
